<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="魔镜,文档,">










<meta name="description" content="MagicMirror² 模块开发文档原文地址 本文档介绍了开发MagicMirror²模块的方法目录：  模块结构 文件   核心模块文件：modulename.js   可用的模块实例属性 可继承的模块方法 模块实例方法   Node Helper:node_helper.js 可用的模块实例属性 可继承的模块方法 模块实例方法   MagicMirror 辅助方法 模块选择   MagicM">
<meta name="keywords" content="魔镜,文档">
<meta property="og:type" content="article">
<meta property="og:title" content="MagicMirror²模块开发文档">
<meta property="og:url" content="https://blog.emx6.com/2019/10/22/MagicMirror²模块开发文档/index.html">
<meta property="og:site_name" content="上帝不会掷骰子">
<meta property="og:description" content="MagicMirror² 模块开发文档原文地址 本文档介绍了开发MagicMirror²模块的方法目录：  模块结构 文件   核心模块文件：modulename.js   可用的模块实例属性 可继承的模块方法 模块实例方法   Node Helper:node_helper.js 可用的模块实例属性 可继承的模块方法 模块实例方法   MagicMirror 辅助方法 模块选择   MagicM">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-10-23T16:06:16.995Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="MagicMirror²模块开发文档">
<meta name="twitter:description" content="MagicMirror² 模块开发文档原文地址 本文档介绍了开发MagicMirror²模块的方法目录：  模块结构 文件   核心模块文件：modulename.js   可用的模块实例属性 可继承的模块方法 模块实例方法   Node Helper:node_helper.js 可用的模块实例属性 可继承的模块方法 模块实例方法   MagicMirror 辅助方法 模块选择   MagicM">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://blog.emx6.com/2019/10/22/MagicMirror²模块开发文档/">





  <title>MagicMirror²模块开发文档 | 上帝不会掷骰子</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">上帝不会掷骰子</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-schedule">
          <a href="/schedule/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-calendar"></i> <br>
            
            日程表
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://blog.emx6.com/2019/10/22/MagicMirror²模块开发文档/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Glyn Yu">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="上帝不会掷骰子">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">MagicMirror²模块开发文档</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-10-22T23:19:17+08:00">
                2019-10-22
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/翻译/" itemprop="url" rel="index">
                    <span itemprop="name">翻译</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/2019/10/22/MagicMirror²模块开发文档/#SOHUCS" itemprop="discussionUrl">
                  <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="2019/10/22/MagicMirror²模块开发文档/" itemprop="commentsCount"></span>
                </a>
              
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
            </span>
          

          

          

        </span></div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="MagicMirror²-模块开发文档"><a href="#MagicMirror²-模块开发文档" class="headerlink" title="MagicMirror² 模块开发文档"></a>MagicMirror² 模块开发文档</h1><p><a href="https://github.com/MichMich/MagicMirror/blob/develop/modules/README.md" target="_blank" rel="noopener">原文地址</a></p>
<p>本文档介绍了开发MagicMirror²模块的方法<br>目录：</p>
<ul>
<li>模块结构<ul>
<li>文件</li>
</ul>
</li>
<li>核心模块文件：modulename.js  <ul>
<li>可用的模块实例属性</li>
<li>可继承的模块方法</li>
<li>模块实例方法</li>
</ul>
</li>
<li>Node Helper:node_helper.js<ul>
<li>可用的模块实例属性</li>
<li>可继承的模块方法</li>
<li>模块实例方法</li>
</ul>
</li>
<li>MagicMirror 辅助方法<ul>
<li>模块选择</li>
</ul>
</li>
<li>MagicMirror 日志记录</li>
</ul>
<hr>
<h2 id="建议"><a href="#建议" class="headerlink" title="建议"></a>建议</h2><p>随着魔镜项目取得了巨大的关注，可用的第三方模块也越来越多。对于新用户和开发者来说，为了去了解一个模块究竟做了什么、长什么样以及它的依赖，要花费很多时间在众多的项目仓库中浏览。不幸的是，这些信息仍难以获得，除非你先安装好它。因此<strong>我们强烈建议你在README文件中包含以下信息。</strong></p>
<ul>
<li>一张你开发的模块的高质量截图</li>
<li>用简短的一句话描述它做了什么</li>
<li>它调用了哪些API，包括web链接</li>
<li>API和请求是否需要密钥以及是否有用户限制</li>
</ul>
<p>当然，这也能帮助你更好地认识和改善你的工作。</p>
<h2 id="模块结构"><a href="#模块结构" class="headerlink" title="模块结构"></a>模块结构</h2><p>所有的模块都在<code>modules</code>文件夹中加载。默认模块都放在<code>modules/default</code>文件夹下。你的模块也应该放在modules下。注意在moduls文件下的文件会被git忽略，这样的话在升级MagicMirror² 的时候就不会丢失它们。</p>
<p>一个模块可以单独放在一个文件夹下，多个模块也可以分组放在一个子文件夹下。注意模块的名字需要是唯一的，即使将名称相似的模块放在不同的文件夹中，也不能同时加载它们。</p>
<h3 id="文件"><a href="#文件" class="headerlink" title="文件"></a>文件</h3><ul>
<li><strong>modulename/modulename.js</strong> -这是模块的核心文件</li>
<li><strong>modulename/node_helper.js</strong> -这是一个可选的辅助文件，它将被node脚本加载。node helper会和模块的脚本通过socket系统进行通信。</li>
<li><strong>modulename/public</strong> 任何在这个目录下的文件都可以通过浏览器访问<code>/modulename/filename.ext.</code></li>
<li><strong>modulename/anyfileorfolder</strong>这里放置会被核心脚本用到的一些文件。例如<code>modulename/css/modulename.css</code>就是用来放置样式表的一个很好路径</li>
</ul>
<h2 id="模块核心文件：modulename-js"><a href="#模块核心文件：modulename-js" class="headerlink" title="模块核心文件：modulename.js"></a>模块核心文件：modulename.js</h2><p>模块将在这个脚本中被定义。要使用模块的话，这个脚本不可或缺。最简单的形式，核心文件必须包括：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Module.register(<span class="string">"modulename"</span>,&#123;&#125;);</span><br></pre></td></tr></table></figure>

<p>当然，上面这个模块不会做任何事情，所以还是看一下最简单的一个模块：<strong>helloworld</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//helloworld.js:</span></span><br><span class="line"></span><br><span class="line">Module.register(<span class="string">"helloworld"</span>,&#123;</span><br><span class="line">	<span class="comment">// Default module config.</span></span><br><span class="line">	defaults: &#123;</span><br><span class="line">		text: <span class="string">"Hello World!"</span></span><br><span class="line">	&#125;,</span><br><span class="line"></span><br><span class="line">	<span class="comment">// Override dom generator.</span></span><br><span class="line">	getDom: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">		<span class="keyword">var</span> wrapper = <span class="built_in">document</span>.createElement(<span class="string">"div"</span>);</span><br><span class="line">		wrapper.innerHTML = <span class="keyword">this</span>.config.text;</span><br><span class="line">		<span class="keyword">return</span> wrapper;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>你能够看到，<code>Module.register()</code>方法接受两个参数：模块的名称和一个描述模块属性的对象。</p>
<p>###　可用的模块实例属性</p>
<p>在模块被初始化之后，模块实例有一些可用的属性:</p>
<table>
<thead>
<tr>
<th align="left">实例属性</th>
<th align="left">类型</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>this.name</code></td>
<td align="left">String</td>
<td align="left">模块名称</td>
</tr>
<tr>
<td align="left"><code>this.identifier</code></td>
<td align="left">String</td>
<td align="left">模块实例的唯一标识</td>
</tr>
<tr>
<td align="left"><code>this.hidden</code></td>
<td align="left">Boolean</td>
<td align="left">这个代表模块现在是否被隐藏</td>
</tr>
<tr>
<td align="left"><code>this.config</code></td>
<td align="left">Boolean ???</td>
<td align="left">用户在<code>config.js</code>中设置的配置。如果这个属性没有被用户配置覆盖的话，这个配置也包括模块的默认配置</td>
</tr>
<tr>
<td align="left"><code>this.data</code></td>
<td align="left">Object</td>
<td align="left">data对象包括一个额外的元数据（见下）</td>
</tr>
</tbody></table>
<p><code>this.data</code>包括以下元数据：</p>
<ul>
<li><code>data.classes</code> - modules的dom wrapper的class</li>
<li><code>data.file</code> - 模块核心文件的名称</li>
<li><code>data.path</code> - 模块所在的目录路径</li>
<li><code>data.header</code> - 加到模块？？？？</li>
<li><code>data.postion</code> - 模块实例将显示的位置</li>
</ul>
<h4 id="default："><a href="#default：" class="headerlink" title="default：{}"></a><code>default：{}</code></h4><p>任何在default对象中定义的对象，都会被合并到用户的<code>config.js</code>中的模块配置中。这里是你设置模块默认配置的最佳位置。所有的模块配置属性都可以通过<code>this.config.propertyName</code>获取，这会在之后提到。</p>
<h4 id="requireVersion："><a href="#requireVersion：" class="headerlink" title="requireVersion："></a>requireVersion：</h4><p>版本：2.1.0<br>定义MagicMirror框架的最低版本。如果它被设置了，系统会把这个版本号和用户的版本进行比较，如果用户版本较低，就不会运行这个模块。确保在Node helper中也设置了这个值。</p>
<p><strong>注意</strong>：因为这个检查设置是在2.1.0版本中介绍的，这个操作不会在更老的版本中执行。<br>Example：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">requiresVersion: <span class="string">"2.1.0"</span>,</span><br></pre></td></tr></table></figure>

<h3 id="可继承的模块方法"><a href="#可继承的模块方法" class="headerlink" title="可继承的模块方法"></a>可继承的模块方法</h3><h4 id="init"><a href="#init" class="headerlink" title="init()"></a>init()</h4><p>这个放在在模块取得实例时被调用。在多数情况下，你不需要去继承这个方法。</p>
<h4 id="loaded-callback"><a href="#loaded-callback" class="headerlink" title="loaded(callback)"></a>loaded(callback)</h4><p>版本：2.1.1<br>此方法在模块被加载后调用。在配置中之后的模块现在还没有被加载。<code>callback</code>中的函数必须在模块被加载完后被调用。在多数情况下你不需要继承此方法。<br><strong>Example:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">loaded: <span class="function"><span class="keyword">function</span>(<span class="params">callback</span>) </span>&#123;</span><br><span class="line">	<span class="keyword">this</span>.finishLoading();</span><br><span class="line">	Log.log(<span class="keyword">this</span>.name + <span class="string">' is loaded!'</span>);</span><br><span class="line">	callback();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="start"><a href="#start" class="headerlink" title="start()"></a>start()</h4><p>这个方法在所有模块都被加载好并且系统准备系统时加载。注意这个时候dom对象还没有被创建。start方法可用来定义模块其他属性。<br><strong>Example:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">start: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="keyword">this</span>.mySpecialProperty = <span class="string">"So much wow!"</span>;</span><br><span class="line">	Log.log(<span class="keyword">this</span>.name + <span class="string">' is started!'</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="getScript"><a href="#getScript" class="headerlink" title="getScript()"></a>getScript()</h4><p><strong>返回：Array</strong><br>getScript方法用来加载任何额外的脚本。这个方法需要返回一个字符串数组。如果你想放回一个module目录下的文件路径，使用<code>this.file(&#39;file.name.js&#39;)</code>方法。在任何情况下，加载器只会加载一次文件。它也会检查文件在vendor文件夹下是否存在。<br><strong>Example</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">getScripts: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="keyword">return</span> [</span><br><span class="line">		<span class="string">'script.js'</span>, <span class="comment">// will try to load it from the vendor folder, otherwise it will load is from the module folder.</span></span><br><span class="line">		<span class="string">'moment.js'</span>, <span class="comment">// this file is available in the vendor folder, so it doesn't need to be available in the module folder.</span></span><br><span class="line">		<span class="keyword">this</span>.file(<span class="string">'anotherfile.js'</span>), <span class="comment">// this file will be loaded straight from the module folder.</span></span><br><span class="line">		<span class="string">'https://code.jquery.com/jquery-2.2.3.min.js'</span>,  <span class="comment">// this file will be loaded from the jquery servers.</span></span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>注意</strong>:如果某个文件不能被加载，魔镜的启动会被阻塞。所以，建议不要使用外部的url。</p>
<h4 id="getStyles"><a href="#getStyles" class="headerlink" title="getStyles()"></a>getStyles()</h4><p><strong>返回：Array</strong><br>getStyle方法用来加载额外的样式文件。这个方法需要返回一个字符串数组。如果你想放回一个module目录下的文件路径，使用<code>this.file(&#39;file.name.css&#39;)</code>方法。在任何情况下，加载器只会加载一次文件。它也会检查文件在vendor文件夹下是否存在。</p>
<p><strong>Example</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">getStyles: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="keyword">return</span> [</span><br><span class="line">		<span class="string">'script.css'</span>, <span class="comment">// will try to load it from the vendor folder, otherwise it will load is from the module folder.</span></span><br><span class="line">		<span class="string">'font-awesome.css'</span>, <span class="comment">// this file is available in the vendor folder, so it doesn't need to be available in the module folder.</span></span><br><span class="line">		<span class="keyword">this</span>.file(<span class="string">'anotherfile.css'</span>), <span class="comment">// this file will be loaded straight from the module folder.</span></span><br><span class="line">		<span class="string">'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'</span>,  <span class="comment">// this file will be loaded from the bootstrapcdn servers.</span></span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>注意</strong>:如果某个文件不能被加载，魔镜的启动会被阻塞。所以，建议不要使用外部的url。</p>
<h4 id="getTranslations"><a href="#getTranslations" class="headerlink" title="getTranslations()"></a>getTranslations()</h4><p><strong>返回：Dictionary</strong><br>getTranslations方法用来请求需要加载的翻译文件。这个方法需要返回用国家代号做键名的的字典。<br>如果模块没有特定的语言文件，这个函数会被忽略或者返回<code>false</code>。
<strong>Example：</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">getTranslations: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="keyword">return</span> &#123;</span><br><span class="line">			en: <span class="string">"translations/en.json"</span>,</span><br><span class="line">			de: <span class="string">"translations/de.json"</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="getDom"><a href="#getDom" class="headerlink" title="getDom()"></a>getDom()</h4><p><strong>返回：Dom对象</strong><br>当MagicMirror需要在屏幕上更新信息时(在它启动时，或者因为你的模块使用<code>this.updateDom()</code>请求刷新时)，系统会调用getDom方法。这个方法需要返回一个Dom对象。<br><strong>Example：</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">getDom: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="keyword">var</span> wrapper = <span class="built_in">document</span>.createElement(<span class="string">"div"</span>);</span><br><span class="line">	wrapper.innerHTML = <span class="string">'Hello world!'</span>;</span><br><span class="line">	<span class="keyword">return</span> wrapper;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="getHeader"><a href="#getHeader" class="headerlink" title="getHeader()"></a>getHeader()</h4><p><strong>返回：String</strong><br>当MagicMirror需要在屏幕上更新信息时(在它启动时，或者因为你的模块使用<code>this.updateDom()</code>请求刷新时)，系统会调用getHeader方法去获取模块的头部信息。这个方法要求返回一个字符串。如果这个方法没有被继承，这个方法将返回用户配置的头部信息。<br>如果你想使用用户配置的头部信息，参考<code>this.data.header</code><br><strong>注意</strong>：如果你没有配置默认的头部信息，没有头部信息会被显示，并且这个方法不会被调用。<br><strong>Example：</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">getHeader: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="keyword">return</span> <span class="keyword">this</span>.data.header + <span class="string">' Foo Bar'</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="notificationReceived-notification-payload-sender"><a href="#notificationReceived-notification-payload-sender" class="headerlink" title="notificationReceived(notification, payload, sender)"></a>notificationReceived(notification, payload, sender)</h4><p>MagicMirror核心有能力给模块发送通知，甚至是一个模块可以给另一个模块发送通知。当这个函数被调用后，它有三个参数：</p>
<ul>
<li><code>notification</code> - String - 通知的标识</li>
<li><code>payload</code>- AnyType - 通知的负载</li>
<li><code>sender</code> - Module - 通知的发送方，如果这个参数是<code>undefined</code>，那么通知的发送方是核心系统。</li>
</ul>
<p><strong>Example:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"> notificationReceived: <span class="function"><span class="keyword">function</span>(<span class="params">notification, payload, sender</span>) </span>&#123;</span><br><span class="line">	<span class="keyword">if</span> (sender) &#123;</span><br><span class="line">		Log.log(<span class="keyword">this</span>.name + <span class="string">" received a module notification: "</span> + notification + <span class="string">" from sender: "</span> + sender.name);</span><br><span class="line">	&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">		Log.log(<span class="keyword">this</span>.name + <span class="string">" received a system notification: "</span> + notification);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>注意:</strong>系统会在启动时发送三个通知。这个通知可能会派上用场。</p>
<ul>
<li><code>ALL_MODULES_STARTED</code> - 所有模块被系统，你现在可以给其他模块发送消息。</li>
<li><code>DOM_OBJECTS_CREATED</code> - 所有的Dom对象被创建，系统现在可以进行视觉上的改变。</li>
<li><code>MODULE_DOM_CREATED</code> - 这个模块的Dom已经被全部加载，你现在可以访问你的Dom对象。</li>
</ul>
<h4 id="socketNotificationRceived-function-notification-payload"><a href="#socketNotificationRceived-function-notification-payload" class="headerlink" title="socketNotificationRceived: function(notification, payload)"></a>socketNotificationRceived: function(notification, payload)</h4><p>当使用node_helper时，node_helper能够给你的模块发送信息，当这个模块被调用时，它有两个参数：</p>
<ul>
<li><code>notification</code> - String - 通知的标识</li>
<li><code>payload</code> - AnyType - 通知的负载</li>
</ul>
<p><strong>注意1</strong>:当node helper发送一个通知时，所有这个模块类型的模块都会收到相同的通知。<br><strong>注意2</strong>：当模块第一次使用sendSocketNotification发送信息时，socket链接就被建立。</p>
<p><strong>Example:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">socketNotificationReceived: <span class="function"><span class="keyword">function</span>(<span class="params">notification, payload</span>) </span>&#123;</span><br><span class="line">	Log.log(<span class="keyword">this</span>.name + <span class="string">" received a socket notification: "</span> + notification + <span class="string">" - Payload: "</span> + payload);</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>

<p>####　suspend()</p>
<p>当一个模块被隐藏时(使用<code>module.hide()</code>),<code>suspend()</code>方法会被调用。通过继承这个方法，你可以进行一些像中止更新计时器的操作。</p>
<h4 id="resume"><a href="#resume" class="headerlink" title="resume()"></a>resume()</h4><p>当一个模块被显示时(使用<code>module.show()</code>),<code>resume()</code>方法会被调用。通过继承这个方法，你可以进行一些像重启更新计时器的操作。</p>
<h3 id="模块实例方法"><a href="#模块实例方法" class="headerlink" title="模块实例方法"></a>模块实例方法</h3><p>每个模块实例都有一些对构建模块有帮助的便捷方法。</p>
<h4 id="this-file-filename"><a href="#this-file-filename" class="headerlink" title="this.file(filename)"></a><code>this.file(filename)</code></h4><p><strong>filename String</strong> - 你创建路径的文件的名称<br><strong>返回 String</strong><br>如果你想在你的模块文件夹下创建文件的路径，使用<code>file()</code>方法。//TODO（Is method comes in handy when configuring the getScripts and getStyles methods.）</p>
<h4 id="this-update-speed"><a href="#this-update-speed" class="headerlink" title="this.update(speed)"></a><code>this.update(speed)</code></h4><p><strong>speed Number</strong> - 可选，运动速度 毫秒</p>
<p>当你要更新模块时，调用<code>updateDom(speed)</code>方法。它向MagicMirror核心请求更新它的dom对象。如果你定义的speed，那么内容更新将是延时运动的，不过要内容真的有变化。<br>举例，时钟模块每一秒会调用这个方法：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">start: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="keyword">var</span> self = <span class="keyword">this</span>;</span><br><span class="line">	setInterval(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">		self.updateDom(); <span class="comment">// no speed defined, so it updates instantly.</span></span><br><span class="line">	&#125;, <span class="number">1000</span>); <span class="comment">//perform every 1000 milliseconds.</span></span><br><span class="line">&#125;</span><br><span class="line">...</span><br></pre></td></tr></table></figure>

<h4 id="this-sendNotification-notification-payload"><a href="#this-sendNotification-notification-payload" class="headerlink" title="this.sendNotification(notification, payload)"></a><code>this.sendNotification(notification, payload)</code></h4><p><strong>notification String</strong> - 通知标识<br><strong>payload AnyType</strong> - 可选，通知负载</p>
<p>如果你想给其他模块发送信息，使用<code>sendNotification(notification, payload)</code>。所有的模块都会通过notificationReceived方法收到信息。//TODO In that case, the sender is automatically set to the instance calling the sendNotification method.</p>
<p><strong>Example:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.sendNotification(<span class="string">'MYMODULE_READY_FOR_ACTION'</span>, &#123;<span class="attr">foo</span>:bar&#125;);</span><br></pre></td></tr></table></figure>

<h4 id="this-sendSocketNotification-notification-payload"><a href="#this-sendSocketNotification-notification-payload" class="headerlink" title="this.sendSocketNotification(notification, payload)"></a><code>this.sendSocketNotification(notification, payload)</code></h4><p><strong>notification String</strong> - 通知标识<br><strong>payload AnyType</strong> - 可选，通知负载</p>
<p>如果你想给node_helper发送通知，使用<code>endSocketNotification(notification, payload)</code>。只有这个模块的node_helper会收到socket通知。<br><strong>Example:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.sendSocketNotification(<span class="string">'SET_CONFIG'</span>, <span class="keyword">this</span>.config);</span><br></pre></td></tr></table></figure>

<h4 id="this-hide-speed-callback-options"><a href="#this-hide-speed-callback-options" class="headerlink" title="this.hide(speed, callback, options)"></a><code>this.hide(speed, callback, options)</code></h4><ul>
<li><strong>speed Number</strong> - 可选(设置callback或option时需要)，隐藏的动效速度，毫秒。</li>
<li><strong>callback</strong> -可选，在运动结束后的回调</li>
<li><strong>options</strong> - 可选，隐藏操作的额外选项（见下）。（2.1.0）</li>
</ul>
<p>你可以使用<code>hide(speed,callback)</code>方法来隐藏一个模块。你可以在对象实例自身上使用<code>this.hide()</code>，当然你也可以使用<code>anOtherModule.hide()</code>来隐藏其他模块。</p>
<p>可配置的选择项:</p>
<ul>
<li><code>lockString</code> - String 当设置了lock字符，在没有正确的lockstring时模块无法被显示。这样的话可以阻止一个模块被显示。把你的模块标识（this.identifier)作为lockString的方式是好的.（见下）</li>
</ul>
<p><strong>注意1</strong>：如果隐藏动效被取消，这可能因为在隐藏动画结束前调用了显示动画。回调函数不会被取消。<br><strong>注意2</strong>:如果隐藏动效被hijacked(其他方法在这个模块上调用了隐藏方法)，回调函数不会被调用。<br><strong>注意3</strong>:如果dom没有被创建，hide方法不会被调用。等待<code>DOM_OBJECTS_CREATED</code>通知。</p>
<h4 id="this-shwo-speed-callback-options"><a href="#this-shwo-speed-callback-options" class="headerlink" title="this.shwo(speed,callback,options)"></a><code>this.shwo(speed,callback,options)</code></h4><ul>
<li><strong>speed Number</strong> - 可选(设置callback或option时需要)，显示的动效速度，毫秒。</li>
<li><strong>callback</strong> -可选，在运动结束后的回调</li>
<li><strong>options</strong> - 可选，显示操作的额外选项（见下）。（2.1.0）</li>
</ul>
<p>你可以使用<code>show(speed,callback)</code>方法来显示一个模块。你可以在对象实例自身上使用<code>this.show()</code>，当然你也可以使用<code>anOtherModule.show()</code>来显示其他模块。</p>
<p>可选配置：</p>
<ul>
<li><code>lockString</code> - String 当设置了lock字符，在没有正确的lockstring时模块无法被显示。这样的话可以阻止一个模块被显示。把你的模块标识（this.identifier)作为lockString的方式是好的.（见下）</li>
<li><code>force</code> - Boolean 当force标志为<code>true</code>时，locking机制会被覆盖。谨慎使用这个选项。</li>
</ul>
<p><strong>注意1</strong>：如果显示动画被取消，这可能因为在显示动画结束前隐藏动画被调用。回调函数不会被调用。<br><strong>注意2</strong>:如果显示动效被hijacked(其他方法在这个模块上调用了显示方法)，回调函数不会被调用。<br><strong>注意3</strong>:如果dom没有被创建，show方法不会被调用。等待<code>DOM_OBJECTS_CREATED</code>通知。</p>
<h4 id="Visibility-locking"><a href="#Visibility-locking" class="headerlink" title="Visibility locking"></a>Visibility locking</h4><p>版本：2.1.0</p>
<p>Visibility locking 帮助系统阻止不想发生的隐藏/显示操作。以下面的情况为例进行介绍：<br><strong>模块B使模块A隐藏:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moduleA.hide(<span class="number">0</span>, &#123;<span class="attr">lockString</span>: <span class="string">"module_b_identifier"</span>&#125;);</span><br></pre></td></tr></table></figure>

<p>模块A现在是隐藏的，并且有一个这个的锁：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moduleA.lockStrings == [<span class="string">"module_b_identifier"</span>]</span><br><span class="line">moduleA.hidden == <span class="literal">true</span></span><br></pre></td></tr></table></figure>

<p><strong>模块C使模块A隐藏：</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moduleA.hide(<span class="number">0</span>, &#123;<span class="attr">lockString</span>: <span class="string">"module_c_identifier"</span>&#125;);</span><br></pre></td></tr></table></figure>

<p>模块A现在是隐藏的，并且有一个这个的锁：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moduleA.lockStrings == [<span class="string">"module_b_identifier"</span>, <span class="string">"module_c_identifier"</span>]</span><br><span class="line">moduleA.hidden == <span class="literal">true</span></span><br></pre></td></tr></table></figure>

<p><strong>模块B使模块A显示:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moduleA.show(<span class="number">0</span>, &#123;<span class="attr">lockString</span>: <span class="string">"module_b_identifier"</span>&#125;);</span><br></pre></td></tr></table></figure>

<p>lockString 会从模块A的锁中去除，但因为还有一个有效的锁，所以这个模块还是会保持隐藏的状态：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moduleA.lockStrings == [<span class="string">"module_c_identifier"</span>]</span><br><span class="line">moduleA.hidden == <span class="literal">true</span></span><br></pre></td></tr></table></figure>

<p><strong>模块C使模块A显示：</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moduleA.show(<span class="number">0</span>, &#123;<span class="attr">lockString</span>: <span class="string">"module_c_identifier"</span>&#125;);</span><br></pre></td></tr></table></figure>

<p>lockString会从模块A的锁中去除，这会时得锁为空，所以这个模块会被显示：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moduleA.lockStrings == []</span><br><span class="line">moduleA.hidden == <span class="literal">false</span></span><br></pre></td></tr></table></figure>

<p><strong>注意:</strong> locking机制可以被force标志重写覆盖。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">moduleA.show(<span class="number">0</span>, &#123;<span class="attr">force</span>: <span class="literal">true</span>&#125;);</span><br></pre></td></tr></table></figure>

<p>这会重置lockString，模块会被展示</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">moduleA.lockStrings == []</span><br><span class="line">moduleA.hidden == <span class="literal">false</span></span><br></pre></td></tr></table></figure>

<p>谨慎使用<code>force</code>，查看<code>show</code>获取更多信息。</p>
<h4 id="this-translate-identifier"><a href="#this-translate-identifier" class="headerlink" title="this.translate(identifier)"></a>this.translate(identifier)</h4><p><strong>identifier String</strong> - 需要翻译的字符串的标识</p>
<p>魔镜项目为国际化提供了便利的封装。基于用户的语言配置，你可以为你的模块提供不同语言的服务。</p>
<p>如果没有找到语言包，会执行如下的回退操作：</p>
<ul>
<li><ol>
<li>模块语言包中的用户首选语言</li>
</ol>
</li>
<li><ol start="2">
<li>核心语言包中的用户搜选语言</li>
</ol>
</li>
<li><ol start="3">
<li>模块语言包中第一个被定义的语言</li>
</ol>
</li>
<li><ol start="4">
<li>核心语言包中第一个被定义的语言</li>
</ol>
</li>
<li><ol start="5">
<li>语言的标识</li>
</ol>
</li>
</ul>
<p>当给你的模块添加翻译时，最好查看一下在核心翻译文件中是否存在合适的翻译。</p>
<p><strong>Example:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.translate(<span class="string">"INFO"</span>) <span class="comment">//Will return a translated string for the identifier INFO</span></span><br></pre></td></tr></table></figure>

<p><strong>Example json file:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"INFO"</span>: <span class="string">"Really important information!"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>注意</strong>:虽然JSON文件不支持注释，但MagicMirror允许在解析JSON文件之前删除注释。翻译文件中的注释可以帮助其他译者。</p>
<h4 id="this-translate-identifier-variables"><a href="#this-translate-identifier-variables" class="headerlink" title="this.translate(identifier,variables)"></a><code>this.translate(identifier,variables)</code></h4><p><strong>identifier String</strong> - 需要被翻译的字符串的标识。<br><strong>variables Object</strong> - 在翻译中要用到的变量<br>这种改进的，向后兼容的翻译方法和普通的翻译方法一样并且遵循以上的规则。我们推荐使用这个的格式。它允许翻译者改变翻译句子的单词顺序。<br><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> timeUntilEnd = moment(event.endDate, <span class="string">"x"</span>).fromNow(<span class="literal">true</span>);</span><br><span class="line"><span class="keyword">this</span>.translate(<span class="string">"RUNNING"</span>, &#123; <span class="string">"timeUntilEnd"</span>: timeUntilEnd) &#125;); <span class="comment">// Will return a translated string for the identifier RUNNING, replacing `&#123;timeUntilEnd&#125;` with the contents of the variable `timeUntilEnd` in the order that translator intended.</span></span><br></pre></td></tr></table></figure>

<p><strong>Example English .json file:</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	<span class="string">"RUNNING"</span>: <span class="string">"Ends in &#123;timeUntilEnd&#125;"</span>,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>Example Finnish .json file:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	<span class="string">"RUNNING"</span>: <span class="string">"Päättyy &#123;timeUntilEnd&#125; päästä"</span>,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>注意</strong>:variable对象有一个特殊的情况：<code>fallback</code>。它用于支持翻译文件中没有变量的旧翻译。如果你正在升级一个旧模块，并且这个模块的翻译不支持语序，那么我们推荐使用fallback<br><strong>Example</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> timeUntilEnd = moment(event.endDate, <span class="string">"x"</span>).fromNow(<span class="literal">true</span>);</span><br><span class="line"><span class="keyword">this</span>.translate(<span class="string">"RUNNING"</span>, &#123;</span><br><span class="line">	<span class="string">"fallback"</span>: <span class="keyword">this</span>.translate(<span class="string">"RUNNING"</span>) + <span class="string">" &#123;timeUntilEnd&#125;"</span></span><br><span class="line">	<span class="string">"timeUntilEnd"</span>: timeUntilEnd</span><br><span class="line">)&#125;); <span class="comment">// Will return a translated string for the identifier RUNNING, replacing `&#123;timeUntilEnd&#125;` with the contents of the variable `timeUntilEnd` in the order that translator intended. (has a fallback)</span></span><br></pre></td></tr></table></figure>

<p><strong>Example Swedish .json file that does not have the variable in it:</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	<span class="string">"RUNNING"</span>: <span class="string">"Slutar"</span>,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>在这种情况下，translate方法不会在翻译中找到任何变量，而是寻找<code>fallback</code>变量，并在可能的情况下使用它来创建翻译。</p>
<h2 id="The-Node-Helper-node-helper-js"><a href="#The-Node-Helper-node-helper-js" class="headerlink" title="The Node Helper: node_helper.js"></a>The Node Helper: node_helper.js</h2><p>node helper是一个node.js脚本，它可以通过一些后端任务来支持你的模块。对于每一个模块类型，只有一个node helper会被创建。例如：如果你的魔镜有两个日历模块，那么只有一个node helper实例。</p>
<p>node_helper.js的最简单的形式必须包括：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> NodeHelper = <span class="built_in">require</span>(<span class="string">"node_helper"</span>);</span><br><span class="line"><span class="built_in">module</span>.exports = NodeHelper.create(&#123;&#125;);</span><br></pre></td></tr></table></figure>

<p>当然，上面的node helper不会做任何有用的事情。有了上面的信息，你应该可以让它更加复杂了。</p>
<h3 id="可用的模块实例属性"><a href="#可用的模块实例属性" class="headerlink" title="可用的模块实例属性"></a>可用的模块实例属性</h3><h4 id="this-name"><a href="#this-name" class="headerlink" title="this.name"></a><code>this.name</code></h4><p><strong>String</strong><br>模块的名称</p>
<h4 id="this-path"><a href="#this-path" class="headerlink" title="this.path"></a>this.path</h4><p><strong>String</strong><br>模块的路径</p>
<h4 id="this-expressApp"><a href="#this-expressApp" class="headerlink" title="this.expressApp"></a>this.expressApp</h4><p>Express App Instance<br>这是一个express实例的链接，允许你定义额外的路由。<br><strong>Example</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">start: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="keyword">this</span>.expressApp.get(<span class="string">'/foobar'</span>, <span class="function"><span class="keyword">function</span> (<span class="params">req, res</span>) </span>&#123;</span><br><span class="line">		res.send(<span class="string">'GET request to /foobar'</span>);</span><br><span class="line">	&#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>注意：</strong>默认情况下，你的模块的public文件夹的路径会被定义：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.expressApp.use(<span class="string">"/"</span> + <span class="keyword">this</span>.name, express.static(<span class="keyword">this</span>.path + <span class="string">"/public"</span>));</span><br></pre></td></tr></table></figure>

<h4 id="this-io"><a href="#this-io" class="headerlink" title="this.io"></a><code>this.io</code></h4><p><strong>Socket IO Instance</strong><br>这是一个IO实例的链接，它允许你进行一些Socket.IO操作。在多数情况下，你用不到它，因为Node Helper有一些更加方便的方法。</p>
<h4 id="requireVersion"><a href="#requireVersion" class="headerlink" title="requireVersion"></a><code>requireVersion</code></h4><p>版本：2.1.0</p>
<p>一个描述MagicMirror框架最低版本的字符串。如果它被设置了，系统会把这个版本号和用户的版本进行比较，如果用户版本较低，就不会运行这个模块。</p>
<p><strong>注意</strong>：因为这个检查设置是在2.1.0版本中介绍的，这个操作不会在更老的版本中执行。<br>Example：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">requiresVersion: <span class="string">"2.1.0"</span>,</span><br></pre></td></tr></table></figure>

<p>###　可继承的模块方法</p>
<h4 id="init-1"><a href="#init-1" class="headerlink" title="init()"></a><code>init()</code></h4><p>当node helper被实例化后这个方法被调用，在多数情况下你不需要继承这个方法。</p>
<h4 id="start-1"><a href="#start-1" class="headerlink" title="start()"></a><code>start()</code></h4><p>这个方法在node helper被加载好并且系统准备系统时调用。start方法可以用来定义额外的模块属性。</p>
<p><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">start: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="keyword">this</span>.mySpecialProperty = <span class="string">"So much wow!"</span>;</span><br><span class="line">	Log.log(<span class="keyword">this</span>.name + <span class="string">' is started!'</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="stop"><a href="#stop" class="headerlink" title="stop()"></a><code>stop()</code></h4><p>这个方法在MagicMirror服务接收到信号指令并且开始关闭时执行。这个方法需要包括所有需要的指令去关闭已开启的连接、停止所有的子进程并且使各模块静默退出。</p>
<p><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">stop: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="built_in">console</span>.log(<span class="string">"Shutting down MyModule"</span>);</span><br><span class="line">	<span class="keyword">this</span>.connection.close();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="socketNotificationReceived-function-notification-payload"><a href="#socketNotificationReceived-function-notification-payload" class="headerlink" title="socketNotificationReceived: function(notification, payload)"></a><code>socketNotificationReceived: function(notification, payload)</code></h4><p>利用这个方法，你的node helper能够接收来自的你模块的通知。这个模块被调用时，它有两个参数：</p>
<ul>
<li><code>notification</code> - String - 通知的标识</li>
<li><code>payload</code> - AnyType - 通知的负载</li>
</ul>
<p><strong>注意:</strong> socket连接会在模块使用sendSocketNotification发送第一个信息时就创建</p>
<p><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">socketNotificationReceived: <span class="function"><span class="keyword">function</span>(<span class="params">notification, payload</span>) </span>&#123;</span><br><span class="line">	Log.log(<span class="keyword">this</span>.name + <span class="string">" received a socket notification: "</span> + notification + <span class="string">" - Payload: "</span> + payload);</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>

<p>###　模块实例方法</p>
<p>每个node helper都有一些能帮助你更好构建模块的便利方法。</p>
<p>####　<code>this.sendSocketNotification(notification,payload)</code></p>
<p><strong>notification String</strong> - 通知的标识<br><strong>payload AnyType</strong> - 可选　通知的负载</p>
<p>如果你想给你所有的模块发送通知，使用<code>sendSocketNotification(notification, payload)</code>,只有你模块类型的模块会接受到socket通知。</p>
<p><strong>注意:</strong> 因为所有的模块实例都会收到通知，确保正确的模块响应你的信息是你的任务。</p>
<p><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.sendSocketNotification(<span class="string">'SET_CONFIG'</span>, <span class="keyword">this</span>.config);</span><br></pre></td></tr></table></figure>

<h2 id="MagicMirror辅助方法"><a href="#MagicMirror辅助方法" class="headerlink" title="MagicMirror辅助方法"></a>MagicMirror辅助方法</h2><p>MagicMirror核心对象：<code>MM</code>有一些便携方法能帮助你更好的把控你的模块。大多数的<code>MM</code>方法都可以在你的模块实例上获取。</p>
<p>###　模块选择</p>
<p>你的模块唯一的附加方法就是获取其他模块的引用。这可以用来隐藏或显示其他模块。</p>
<h4 id="MM-getModules"><a href="#MM-getModules" class="headerlink" title="MM.getModules()"></a><code>MM.getModules()</code></h4><p><strong>返回 Array</strong> - 模块实例的数组</p>
<p>使用<code>MM.getModules()</code>方法选择所有被加载的模块实例。它会返回一个现在已经被加载的模块实例的数组。返回的数组有一些筛选方法，见下。</p>
<h5 id="withClass-classnames"><a href="#withClass-classnames" class="headerlink" title=".withClass(classnames)"></a><code>.withClass(classnames)</code></h5><p><strong>classnames String or Array</strong> - 你想要筛选的类名称。<br><strong>返回 Array</strong> - 一个模块实例数组</p>
<p>如果你想基于一个或多个类名称进行筛选，在<code>MM。getModules()</code>方法后使用withClass方法。它的参数可以是一个数组，或者用空格分割的字符串。</p>
<p><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> modules = MM.getModules().withClass(<span class="string">'classname'</span>);</span><br><span class="line"><span class="keyword">var</span> modules = MM.getModules().withClass(<span class="string">'classname1 classname2'</span>);</span><br><span class="line"><span class="keyword">var</span> modules = MM.getModules().withClass([<span class="string">'classname1'</span>,<span class="string">'classname2'</span>]);</span><br></pre></td></tr></table></figure>

<h5 id="exceptWithClass-classname"><a href="#exceptWithClass-classname" class="headerlink" title=".exceptWithClass(classname)"></a><code>.exceptWithClass(classname)</code></h5><p><strong>classnames String or Array</strong> - 你想从结果中移去的模块类名称<br><strong>返回 Array</strong> - 模块实例数组</p>
<p>如果你想基于类名称从选择集合中删去一些模块，在<code>MM。getModules()</code>方法后使用exceptWithClass方法。它的参数可以是一个数组，或者用空格分割的字符串。</p>
<p><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> modules = MM.getModules().exceptWithClass(<span class="string">'classname'</span>);</span><br><span class="line"><span class="keyword">var</span> modules = MM.getModules().exceptWithClass(<span class="string">'classname1 classname2'</span>);</span><br><span class="line"><span class="keyword">var</span> modules = MM.getModules().exceptWithClass([<span class="string">'classname1'</span>,<span class="string">'classname2'</span>]);</span><br></pre></td></tr></table></figure>

<p>#####　<code>.exceptModule(module)</code><br><strong>module Module Object</strong> - 你想从结果中移去的模块的引用。<br><strong>返回 Array</strong> - 模块实例数组</p>
<p>此处原文有误。</p>
<p>如果你想筛选出除了自身的所有模块，这个方法会很有用。</p>
<p><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> modules = MM.getModules().exceptModule(<span class="keyword">this</span>);</span><br></pre></td></tr></table></figure>

<p>当然，你可以把以上选择器结合起来：<br><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> modules = MM.getModules().withClass(<span class="string">'classname1'</span>).exceptwithClass(<span class="string">'classname2'</span>).exceptModule(aModule);</span><br></pre></td></tr></table></figure>

<p>#####　<code>.enumerate(callback)</code></p>
<p><strong>callback Function(module)</strong> - 每一个实例上的回调</p>
<p>如果你想在所有选择好的模块删执行一个操作，你可以使用<code>enumerate</code>函数:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">MM.getModules().enumerate(<span class="function"><span class="keyword">function</span>(<span class="params">module</span>) </span>&#123;</span><br><span class="line">    Log.log(<span class="built_in">module</span>.name);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p><strong>Example</strong>: 要隐藏除了自身的其他模块，你可以这么写：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">Module.register(<span class="string">"modulename"</span>,&#123;</span><br><span class="line">	<span class="comment">//...</span></span><br><span class="line">	notificationReceived: <span class="function"><span class="keyword">function</span>(<span class="params">notification, payload, sender</span>) </span>&#123;</span><br><span class="line">		<span class="keyword">if</span> (notification === <span class="string">'DOM_OBJECTS_CREATED'</span>) &#123;</span><br><span class="line">			MM.getModules().exceptModule(<span class="keyword">this</span>).enumerate(<span class="function"><span class="keyword">function</span>(<span class="params">module</span>) </span>&#123;</span><br><span class="line">				<span class="built_in">module</span>.hide(<span class="number">1000</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">					<span class="comment">//Module hidden.</span></span><br><span class="line">				&#125;);</span><br><span class="line">			&#125;);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="comment">//...</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<h2 id="MagicMirror日志记录"><a href="#MagicMirror日志记录" class="headerlink" title="MagicMirror日志记录"></a>MagicMirror日志记录</h2><p>MagicMirror项目对log做了方便的封装。目前，这只是对原生的<code>console.log</code>的简单代理，但是之后可能会增加一些额外的特性。现在，log只在模块核心文件中有效(不包括node_helper)</p>
<p><strong>Example</strong>:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Log.info(<span class="string">'error'</span>);</span><br><span class="line">Log.log(<span class="string">'log'</span>);</span><br><span class="line">Log.error(<span class="string">'info'</span>);</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/魔镜/" rel="tag"># 魔镜</a>
          
            <a href="/tags/文档/" rel="tag"># 文档</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/10/11/魔镜开发日记-三-pusher-Python-Client/" rel="next" title="魔镜开发日记(三)--pusher-Python-Client">
                <i class="fa fa-chevron-left"></i> 魔镜开发日记(三)--pusher-Python-Client
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/11/12/js设计模式-工厂模式/" rel="prev" title="js设计模式-工厂模式">
                js设计模式-工厂模式 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Glyn Yu</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">26</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">48</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zjycp" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:chnzjycp@foxmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#MagicMirror²-模块开发文档"><span class="nav-number">1.</span> <span class="nav-text">MagicMirror² 模块开发文档</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#建议"><span class="nav-number">1.1.</span> <span class="nav-text">建议</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#模块结构"><span class="nav-number">1.2.</span> <span class="nav-text">模块结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#文件"><span class="nav-number">1.2.1.</span> <span class="nav-text">文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#模块核心文件：modulename-js"><span class="nav-number">1.3.</span> <span class="nav-text">模块核心文件：modulename.js</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#default："><span class="nav-number">1.3.0.1.</span> <span class="nav-text">default：{}</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#requireVersion："><span class="nav-number">1.3.0.2.</span> <span class="nav-text">requireVersion：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#可继承的模块方法"><span class="nav-number">1.3.1.</span> <span class="nav-text">可继承的模块方法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#init"><span class="nav-number">1.3.1.1.</span> <span class="nav-text">init()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#loaded-callback"><span class="nav-number">1.3.1.2.</span> <span class="nav-text">loaded(callback)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#start"><span class="nav-number">1.3.1.3.</span> <span class="nav-text">start()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#getScript"><span class="nav-number">1.3.1.4.</span> <span class="nav-text">getScript()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#getStyles"><span class="nav-number">1.3.1.5.</span> <span class="nav-text">getStyles()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#getTranslations"><span class="nav-number">1.3.1.6.</span> <span class="nav-text">getTranslations()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#getDom"><span class="nav-number">1.3.1.7.</span> <span class="nav-text">getDom()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#getHeader"><span class="nav-number">1.3.1.8.</span> <span class="nav-text">getHeader()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#notificationReceived-notification-payload-sender"><span class="nav-number">1.3.1.9.</span> <span class="nav-text">notificationReceived(notification, payload, sender)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#socketNotificationRceived-function-notification-payload"><span class="nav-number">1.3.1.10.</span> <span class="nav-text">socketNotificationRceived: function(notification, payload)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#resume"><span class="nav-number">1.3.1.11.</span> <span class="nav-text">resume()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模块实例方法"><span class="nav-number">1.3.2.</span> <span class="nav-text">模块实例方法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#this-file-filename"><span class="nav-number">1.3.2.1.</span> <span class="nav-text">this.file(filename)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-update-speed"><span class="nav-number">1.3.2.2.</span> <span class="nav-text">this.update(speed)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-sendNotification-notification-payload"><span class="nav-number">1.3.2.3.</span> <span class="nav-text">this.sendNotification(notification, payload)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-sendSocketNotification-notification-payload"><span class="nav-number">1.3.2.4.</span> <span class="nav-text">this.sendSocketNotification(notification, payload)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-hide-speed-callback-options"><span class="nav-number">1.3.2.5.</span> <span class="nav-text">this.hide(speed, callback, options)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-shwo-speed-callback-options"><span class="nav-number">1.3.2.6.</span> <span class="nav-text">this.shwo(speed,callback,options)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Visibility-locking"><span class="nav-number">1.3.2.7.</span> <span class="nav-text">Visibility locking</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-translate-identifier"><span class="nav-number">1.3.2.8.</span> <span class="nav-text">this.translate(identifier)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-translate-identifier-variables"><span class="nav-number">1.3.2.9.</span> <span class="nav-text">this.translate(identifier,variables)</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#The-Node-Helper-node-helper-js"><span class="nav-number">1.4.</span> <span class="nav-text">The Node Helper: node_helper.js</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#可用的模块实例属性"><span class="nav-number">1.4.1.</span> <span class="nav-text">可用的模块实例属性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#this-name"><span class="nav-number">1.4.1.1.</span> <span class="nav-text">this.name</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-path"><span class="nav-number">1.4.1.2.</span> <span class="nav-text">this.path</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-expressApp"><span class="nav-number">1.4.1.3.</span> <span class="nav-text">this.expressApp</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#this-io"><span class="nav-number">1.4.1.4.</span> <span class="nav-text">this.io</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#requireVersion"><span class="nav-number">1.4.1.5.</span> <span class="nav-text">requireVersion</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#init-1"><span class="nav-number">1.4.1.6.</span> <span class="nav-text">init()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#start-1"><span class="nav-number">1.4.1.7.</span> <span class="nav-text">start()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#stop"><span class="nav-number">1.4.1.8.</span> <span class="nav-text">stop()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#socketNotificationReceived-function-notification-payload"><span class="nav-number">1.4.1.9.</span> <span class="nav-text">socketNotificationReceived: function(notification, payload)</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MagicMirror辅助方法"><span class="nav-number">1.5.</span> <span class="nav-text">MagicMirror辅助方法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#MM-getModules"><span class="nav-number">1.5.0.1.</span> <span class="nav-text">MM.getModules()</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#withClass-classnames"><span class="nav-number">1.5.0.1.1.</span> <span class="nav-text">.withClass(classnames)</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#exceptWithClass-classname"><span class="nav-number">1.5.0.1.2.</span> <span class="nav-text">.exceptWithClass(classname)</span></a></li></ol></li></ol></li></ol><li class="nav-item nav-level-2"><a class="nav-link" href="#MagicMirror日志记录"><span class="nav-number">1.6.</span> <span class="nav-text">MagicMirror日志记录</span></a></li></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Glyn Yu</span>

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1277767124&web_id=1277767124" language="JavaScript"></script>
  </div>



        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  




  
    <script type="text/javascript">
    (function(){
      var appid = 'cyuiUNe9o';
      var conf = '7ce07412b2706ea50ada6a787faf513f';
      var width = window.innerWidth || document.documentElement.clientWidth;
      if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){
        window.changyan.api.config({appid:appid,conf:conf})});
      }
    })();
    </script>
    <script type="text/javascript" src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>
  









  





  

  

  

  
  

  

  

  

</body>
</html>
